package com.HomeWork;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * 定义一个火车票类  包含票号，出发地，目的地，票价，列车编号，出发时间等属性，重写toString方法
 *    创建一个ArrayList,存储这100个火车票对象，火车票对象中的票号分别用1--100表示，
 *    其它属性允许相同。可用for循环添加火车票对象
 *    用继承Thread类的方式创建3-4个线程卖ArrayList中的火车票，每卖出一张，
 *    移除arrayList中的一个火车票对象，直到ArrayList中的元素为0，表示卖完了
 *    每卖出一张  在控制台打印出   线程-N 卖出了火车票，
 *    调用火车票的toString方法把火车票信息打印出来
 *
 *    用实现Runnable方式重复完成以上操作
 */

class TrainTicks{
    //包含票号，出发地，目的地，票价，列车编号，出发时间等属性
    int TickId ;
    String departurePlace;
    String destination;
    double price;
    String trainId;
    String  goTime;

    public TrainTicks(int tickId, String departurePlace, String destination, double price, String trainId, String  goTime) {
        TickId = tickId;
        this.departurePlace = departurePlace;
        this.destination = destination;
        this.price = price;
        this.trainId = trainId;
        this.goTime = goTime;
    }

    public int getTickId() {
        return TickId;
    }

    public void setTickId(int tickId) {
        TickId = tickId;
    }

    public String getDeparturePlace() {
        return departurePlace;
    }

    public void setDeparturePlace(String departurePlace) {
        this.departurePlace = departurePlace;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getTrainId() {
        return trainId;
    }

    public void setTrainId(String trainId) {
        this.trainId = trainId;
    }

    public String  getGoTime() {
        return goTime;
    }

    public void setGoTime(String  goTime) {
        this.goTime = goTime;
    }

    public TrainTicks() {

    }

    @Override
    public String toString() {
        return "\r\nTrainTicks{" +
                "TickId=" + TickId +
                ", departurePlace='" + departurePlace + '\'' +
                ", destination='" + destination + '\'' +
                ", price=" + price +
                ", trainId='" + trainId + '\'' +
                ", goTime=" + goTime +
                '}';
    }
}
public class work6 extends Thread{
    //创建一个ArrayList,存储这100个火车票对象，火车票对象中的票号分别用1--100表示，
    public static void main(String[] args) throws ParseException {

        ArrayList<TrainTicks> trainTicks1 = new ArrayList<>();
        Date date=new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        String date3 = sdf.format(new Date());
        Date d=sdf.parse(date3);
        System.out.println(d);
        System.out.println(date3);
        for (int i = 1; i <= 10; i++) {
            TrainTicks trainTicks = new TrainTicks();
            trainTicks.setTickId(i);
            trainTicks.setDestination("cs");
            trainTicks.setDeparturePlace("gz");
            trainTicks.setPrice(10+i);
            trainTicks.setTrainId("车"+i);
            trainTicks.setGoTime(date3);
            //System.out.println(trainTicks.toString());
            trainTicks1.add(trainTicks);
        }
        System.out.println(trainTicks1.toString());

        //new Thread()
        work6 t1 = new work6();
        work6 t2 = new work6();
        work6 t3 = new work6();
        work6 t4 = new work6();



    }

    @Override
    public void run() {
      //  while ()




        //super.run();
    }

    public static void mm(){


    }

}
